package multimedia;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

import ui.RecordAudioForm;

/**
 * @author Thiago Bruno Melo de Sales <BR>
 * email: <a href=mailto:thiagobruno@embedded.ufcg.edu.br>thiagobruno@embedded.ufcg.edu.br</a> <BR>
 */
public class ThreadListenAudio implements Runnable {
	
	private byte[] audio;
	
	private RecordAudioForm previous;
	
	public ThreadListenAudio(byte[] audio, RecordAudioForm previous) {
		this.audio = audio;
	}
	
	public void run() {
		InputStream is = new ByteArrayInputStream(audio);
	    Player player;
		try {
			player = Manager.createPlayer(is, "audio/X-wav");
			player.realize();
			player.start();			
		} catch (IOException ioe) {
			ioe.printStackTrace();
			previous.midlet.error(ioe);
		} catch (MediaException me) {
			me.printStackTrace();
			previous.midlet.error(me);
		} catch (SecurityException se) {
			previous.midlet.error(se);
		}
	}

}
